﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace XISoft.AppCreator.Util.ICodeCreator
{
    public class SqlCommon
    {
        public static bool hasInLib(string sqltype)
        {
            ArrayList lsInLibType = new ArrayList();
            ///内置字段
            lsInLibType.Add("int");
            lsInLibType.Add("datetime");
            lsInLibType.Add("iamge");
            lsInLibType.Add("smalldatetime");
            lsInLibType.Add("smallint");
            lsInLibType.Add("bit");
            lsInLibType.Add("bigint");
            lsInLibType.Add("float");
            lsInLibType.Add("decimal");
            lsInLibType.Add("real");
            lsInLibType.Add("money");
            lsInLibType.Add("smallmoney");
            lsInLibType.Add("text");
            lsInLibType.Add("ntext");
            lsInLibType.Add("numeric");
            lsInLibType.Add("tinyint");

            if (lsInLibType.Contains(sqltype))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// 从Java类型转化为SQLServer数据类型
        public static String LanguageToDB(string JavaType)
        {
            string sqlType = "";
            switch (JavaType.ToLower())
            {
                case "int":
                    sqlType = "int";
                    break;
                case "string":
                    sqlType = "nvarchar";
                    break;
                case "double":
                    sqlType = "real";
                    break;
                case "float":
                    sqlType = "real";
                    break;
                case "date":
                    sqlType = "smalldate";
                    break;
            }
            return sqlType;
        }
        public static String DBToLanguage(String dbtype)
        {
            String lanType = String.Empty;
            switch (dbtype.ToLower())
            {
                case "int":
                    lanType = "int";
                    break;
                case "nvarchar":
                    lanType = "string";
                    break;
                case "real":
                    lanType = "double";
                    break;
                case "double":
                    lanType = "double";
                    break;
                case "char":
                    lanType = "string";
                    break;
                default:
                    lanType = "string";
                    break;
            }
            return lanType;
        }
    }
}
